// pages/collect/collect.js
const app = getApp()
const db = wx.cloud.database()
const _ = db.command

Page({

  /**
   * 页面的初始数据
   */
  data: {
    concertList: [],
    collectList: [],
    productList: [
      {
        "id": "1",
        "src": "/images/concert/10.jpg",
        "title": "【广州站】未来有你.初音未来2019中国巡回演唱会",
        "time": "2019.11.23-2019.11.24",
        "location": "广东艺术剧院",
        "price": "840"
      },
      {
        "id": "2",
        "src": "/images/concert/11.jpg",
        "title": "【广州站】未来有你.初音未来2019中国巡回演唱会",
        "time": "2019.11.23-2019.11.24",
        "location": "广东艺术剧院",
        "price": "840"
      },
      {
        "id": "3",
        "src": "/images/concert/12.jpg",
        "title": "【广州站】未来有你.初音未来2019中国巡回演唱会",
        "time": "2019.11.23-2019.11.24",
        "location": "广东艺术剧院",
        "price": "840"
      },
      {
        "id": "4",
        "src": "/images/concert/13.jpg",
        "title": "【广州站】未来有你.初音未来2019中国巡回演唱会",
        "time": "2019.11.23-2019.11.24",
        "location": "广东艺术剧院",
        "price": "840"
      },
      {
        "id": "5",
        "src": "/images/concert/14.jpg",
        "title": "【广州站】未来有你.初音未来2019中国巡回演唱会",
        "time": "2019.11.23-2019.11.24",
        "location": "广东艺术剧院",
        "price": "840"
      },
      {
        "id": "6",
        "src": "/images/concert/15.jpg",
        "title": "【广州站】未来有你.初音未来2019中国巡回演唱会",
        "time": "2019.11.23-2019.11.24",
        "location": "广东艺术剧院",
        "price": "840"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var tempList = []
    this.setData({
      concertList: tempList
    });
  
    wx.cloud.callFunction({
      name: 'getCollection',
      data: {
        collectionName: 'star',
        openid: app.globalData.openid
      },
      success: res => {
        // this.data.isCollect = 0
        console.log(res.result.data)
        for (var i = 0; i < res.result.data.length; i++) {
          this.data.concertList.push(res.result.data[i].concert_Id)
        }
        console.log(this.data.concertList)
        var k = this.data.concertList
        console.log(k)
        wx.cloud.init()
        wx.cloud.callFunction({
          name: 'getCollectionById',
          data: {
            collection: 'concert',
            concertId: k
          },
          success: res => {
            console.log(this.data.collectList)
            this.setData({
              collectList:[]
            })
            var tList=[]
            for(var i =0;i<res.result.data.length;i++){
              tList.push(res.result.data[i])
              console.log(i)
            }
            this.setData({
              collectList:tList
            })
            console.log(this.data.collectList)

          },
          fail: err => {
            console.log(error)
          }
        })
        console.log('getit')
      },
      fail: err => {
        console.error(err)
      }
    })

      console.log(this.data.collectList)

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})